package com.cskaoyan.service;

import com.cskaoyan.mapper.AccountMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author stone
 * @date 2022/08/30 09:14
 */
@Service
public class AccountServiceImpl implements AccountService{

    @Autowired
    AccountMapper accountMapper;

    @Override
    public void transfer(int fromId, int destId, int money) {
        int fromMoney = accountMapper.selectById(fromId);
        int destMoney = accountMapper.selectById(destId);

        fromMoney -= money; // 转出方money减少
        destMoney += money; // 接收方money变多

        accountMapper.updateById(fromMoney, fromId);
         int i = 1 / 0;
        accountMapper.updateById(destMoney, destId);
    }
}
